home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 3.1 KB | 94 lines | [TEXT/MPS ] |
- /*
- File: TSerialSchedulerExample.cp
-
- Contains: This module shows an example of the TSerialScheduler class.
-
- Copyright: © 1993-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TInitSLM.h" // the TInitSLM class and SLM include files
- #include "TSchedulerExample.h"
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// CONSTANTS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- const unsigned kNumofStudents = 8; // no. of students
-
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// GLOBALS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- // array of student names
- char *gStudents[kNumofStudents] ={"John Sculley",
- "Jane Doe ",
- "Bill Clinton",
- "George Bush ",
- "Mick Jagger ",
- "Ren & Stimpy",
- "Joe Montana ",
- "Al Einstein "};
-
- // grades for the above students
- Grade gGrades[kNumofStudents] ={kB, kA, kA, kF, kA, kC, kB, kB};
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// PROTOTYPES
- ///————————————————————————————————————————————————————————————————————————————————————
- static void memory_error();
-
- /*————————————————————————————————————————————————————————————————————————————————————
- main
-
- This example schedules a list of student to be displayed depending to first come
- first serve bases. First it creates a TSerialScheduler, then for each student it
- schedules a TReport operation. This operation once invoked, displays the student's
- name and his/her grade. The operations are executed depending in the order that
- they are scheduled.
- ————————————————————————————————————————————————————————————————————————————————————*/
- main()
- {
- TInitSLM initLibraryManager; // initialize the shared library manager
-
- if( initLibraryManager.Failed() ) // If we failed, let's go home
- return 1;
-
- TReport *thereport[kNumofStudents];
- TSerialScheduler *reportScheduler;
-
- TRY
- reportScheduler = new TSerialScheduler;// create an instance of Serial Scheduler
- FailNULL( reportScheduler, kASLMOutOfMemoryErr, NULL );
-
- // for each student schedule a TOperation to report the grade
- for( short i=0; i<kNumofStudents; i++ ) {
- FailNULL(thereport[i] = new TReport, kASLMOutOfMemoryErr, NULL );
- thereport[i]->NewStudent( gStudents[i] );
- thereport[i]->SetGrade( gGrades[i] );
- reportScheduler->Schedule( thereport[i] );
- }
- // display the report cards in order scheduled
- cout << "Displaying report cards in order scheduled\n" << endl;
- reportScheduler->Run();
-
- delete reportScheduler; // great, we are done now
- CATCH_ALL
- memory_error(); // just in case anything ever failed
- ENDTRY
-
- return 0;
- }
-
- /*————————————————————————————————————————————————————————————————————————————————————
- memory_error
-
- error handler for new.
- ————————————————————————————————————————————————————————————————————————————————————*/
- static void memory_error()
- {
- cout<<"Memory failure, not enough space available" << endl;
- }
-
-